package cn.strive.eams.supplier.service.impl;

import cn.strive.eams.supplier.mapper.SupplierMapper;
import cn.strive.eams.supplier.pojo.dto.SupplierQuery;
import cn.strive.eams.supplier.pojo.dto.SupplierSaveParam;
import cn.strive.eams.supplier.pojo.entity.Supplier;
import cn.strive.eams.supplier.pojo.vo.SupplierVO;
import cn.strive.eams.supplier.service.SupplierService;
import cn.strive.eams.virtual.pojo.entity.Virtual;
import cn.strive.eams.virtual.pojo.vo.VirtualVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;
    @Override
    public List<SupplierVO> selectSupplier(SupplierQuery supplierQuery) {
        log.debug("查询供应商业务:supplierQuery={}",supplierQuery);
        List<SupplierVO>list = supplierMapper.selectSupplier(supplierQuery);
        return list;
    }

    @Override
    public void saveSupplier(SupplierSaveParam supplierSaveParam) {
        log.debug("保存供应商业务:supplierSaveParam={}",supplierSaveParam);
        Supplier supplier = new Supplier();
        BeanUtils.copyProperties(supplierSaveParam,supplier);
        if (supplier.getId() == null){
            supplier.setCreateTime(new Date());
            supplierMapper.insert(supplier);
        }else {
            supplier.setUpdateTime(new Date());
            supplierMapper.update(supplier);
        }
    }

    @Override
    public void deleteSupplier(Long id) {
        log.debug("删除供应商业务:id={}",id);
        supplierMapper.deleteSupplier(id);
    }

    @Override
    public void deleteBatch(List<Long> ids) {
        log.debug("批量删除供应商业务:ids={}", ids);
        for (Long id : ids){
            supplierMapper.deleteSupplier(id);
        }
    }
}
